package day6.wait_and_notify;
/**
 * wait()期间只能释放一把锁
 */
public class Demo2 {
    static Object lock1 = new Object();
    static Object lock2 = new Object();
    static Object lock3 = new Object();

    static class MyThread extends Thread {
        @Override
        public void run() {
            // 抢不到锁，说明lock1没有被释放
            synchronized (lock1) {
                System.out.println("lock1 成功");
            }
//            // 可以抢到锁，说明lock3被释放了
//            synchronized (lock3) {
//                System.out.println("lock3 成功");
//            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        synchronized (lock1) {
            synchronized (lock2) {
                synchronized (lock3) {
                    MyThread t = new MyThread();
                    t.start();

                    // 主线程持有 3 把锁
                    lock3.wait();   // 释放 lock3 锁
                }
            }
        }
    }
}
